//兼容vite require加载
const AdaptRequire: Function = (): void => {
  let env: string = ""
  try {
    if (process.env.NODE_ENV) {
      env = "webpack"
    }
  } catch (error) {
    // console.log(error)
  }

  try {
    if (import.meta.env) {
      env = "vite"
    }
  } catch (error) {
    // console.log(error)
  }

  switch (env) {
    case "webpack":
      break

    case "vite":
      ;(<any>window).require = (path: string): string => {
        let url: string = ""
        try {
          if (path && path.includes("/")) {
            const KEY = path.replace(/@/, "../..")
            return new URL(KEY, import.meta.url).href
          }
        } catch (error) {}

        return url
      }

      break

    default:
      console.log("请在webpack或vite环境中使用")
      break
  }
}
AdaptRequire()

export {}
